﻿namespace KLLSVC
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Configuration;
    using System.Data;
    using System.Diagnostics;
    using System.Linq;
    using System.ServiceProcess;
    using System.Text;

    public partial class RecurringTaskService : ServiceBase
    {
        public RecurringTaskService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            string key_name = string.Empty;
            Help.Log("KLLSVC Start");

            key_name = "TEST_KEY";
            Help.Log(string.Format("{0} has the value of {1}", key_name, ConfigurationManager.AppSettings[key_name]));
            
            key_name = "TIMER_INTERVAL";
            Help.Log(string.Format("{0} has the value of {1}", key_name, ConfigurationManager.AppSettings[key_name]));

            double interval;
            if (double.TryParse(ConfigurationManager.AppSettings[key_name], out interval))
            {
                this.timer.Interval = interval;
            }
        }

        protected override void OnStop()
        {
            Help.Log("KLLSVC Stopped");
        }

        private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            Help.Log("KLLSVC check");

            using (System.Net.WebClient wc = new System.Net.WebClient())
            {
                string url = string.Empty;
                try
                {
                    url = "http://dev.e-overtime.web/";
                    Help.Log(string.Format("Pinging {0}", url));
                    wc.DownloadString(url);
                }
                catch (Exception)
                {
                }

                try
                {
                    url = "http://klwfe03/B2E/e-overtime/";
                    Help.Log(string.Format("Pinging {0}", url));
                    wc.DownloadString(url);
                }
                catch (Exception)
                {
                }
            }
        }
    }
}
